package base.ebay.delayqueuetest;

import java.util.concurrent.DelayQueue;

public class DelayQueueExample {

    public static final DelayQueue<DelayTask> delayQueue = new DelayQueue<>();

    public static void main(String[] args) throws InterruptedException {

        producer();
        consumer();
    }

    public static void producer() {
        delayQueue.add(new DelayTask("任务1", 2000));
        delayQueue.add(new DelayTask("任务2", 800));
        delayQueue.add(new DelayTask("任务3", 1200));
        delayQueue.add(new DelayTask("任务4", 200));
    }

    public static void consumer() throws InterruptedException {
        while (!delayQueue.isEmpty()) {
            DelayTask task = delayQueue.take();
            System.out.println("执行任务：" + task.getTaskName());

        }
    }








}
